var AJAX = {
	
	http : null ,
	formArray : null ,
	_postName : new Array() ,
	_postValue : new Array() ,
	_postStr : null ,
	divOutput : null ,
	divWait : null ,
	
	_createRequestObject : function() {
		if( window.XMLHttpRequest ) {
			return new XMLHttpRequest();
		} else if( window.ActiveXObject ) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			return false;
		}
	} ,
	
	/*constructor*/
	request : function( formArray , url , divOutput , divWait ) {
		this.formArray = formArray;
		this.divOutput = divOutput;
		this.divWait = divWait;
		this.makeData();
		this._request( url );
	} ,
	
	/*create data*/
	makeData : function() {
		
		for( i = 0 ; i < this.formArray.length ; i++ ) {
			
			element = document.getElementById( this.formArray[i] );
			
			if( element.nodeName == 'INPUT' ) {
				if( element.getAttribute('type') == 'radio' && element.checked == true ) {
					this._postValue[ this._postValue.length ] = element.value;
					this._postName[ this._postName.length ] = this.formArray[i];
				} else if( element.getAttribute('type') == 'text' || element.getAttribute('type') == 'password' || element.getAttribute('type') == 'hidden' ) {
					this._postValue[ this._postValue.length ] = element.value;
					this._postName[ this._postName.length ] = this.formArray[i];
				} else if( element.getAttribute('type') == 'checkbox' && element.checked == true ) {
					this._postValue[ this._postValue.length ] = element.value;
					this._postName[ this._postName.length ] = this.formArray[i];
				}
			} else if( element.nodeName == 'SELECT' ) {
				this._postValue[ this._postValue.length ] = element.options[ element.selectedIndex ].value;
				this._postName[ this._postName.length ] = this.formArray[i];
			} else if( element.nodeName == 'TEXTAREA') {
				this._postValue[ this._postValue.length ] = element.value;
				this._postName[ this._postName.length ] = this.formArray[i];
			}
		}
		
		
		this._makePostString();
	} ,
	
	/*make a string of the _post data*/
	_makePostString : function() {
		for( i = 0 ; i < this._postValue.length ; i++ ) {
			if( i == 0 ) {
				this._postStr = this._postName[i] + '=' + encodeURI(this._postValue[i]);
			} else {
				this._postStr += '&' + this._postName[i] + '=' + encodeURI(this._postValue[i]);
			}
		}
	} ,
	
	/*the request*/
	_request : function( url ) {			
			this.http = this._createRequestObject();
			this.http.open('POST' , url , true);
			this.http.onreadystatechange = this.requestHanlder;
			this.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.http.setRequestHeader("Content-length", this._postStr.length);
			this.http.setRequestHeader("Connection", "close");
			this.http.send(this._postStr);
			return true;
	} ,
	
	/*the return of the request*/
	requestHanlder : function() {
		if( AJAX.http.readyState == 4 && AJAX.http.status == 200 && AJAX.http.responseText) {
			document.getElementById( AJAX.divWait ).style.display = 'none';
			document.getElementById( AJAX.divOutput ).innerHTML = AJAX.http.responseText;
			if( AJAX.http.responseText == 'Login correct' ) {
				AjaxTabs.RefreshTab('start');
			}
			else 
			if( AJAX.http.responseText == 'pass changed' ) {
				AjaxTabs.CloseTab(AjaxTabs.GetFocusedTabId());
				alert("het wachtwoord is gewijzigd");
			}


			
		} else {
			document.getElementById( AJAX.divWait ).style.display = 'block';
		}
	}
	
};
